package com.bsoft.exchange.util;

import com.bsoft.exchange.service.PushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component 
@EnableAsync 
public class PushTask {

	@Autowired
	PushService pushService;

	@Value("${push.open}")
	Boolean pushOpen;

	@Scheduled(cron = "${push.cron}")
	@Async 
	public void pushOpenProveNot() {

		if(!pushOpen){
			return;
		}

		System.out.println("定时任务住院证开出通知开始：" +DateUtil.dateFormat(new Date()));
		try{
			pushService.pushOpenProveNot();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("住院证开出通知消息发送失败!");
		}
		System.out.println("定时任务住院证开出通知结束：" +DateUtil.dateFormat(new Date()));
	}

	@Scheduled(cron = "${push.cron}")
	@Async
	public void pushCanceledWorks() {

		if(!pushOpen){
			return;
		}
		System.out.println("定时任务停诊通知开始：" +DateUtil.dateFormat(new Date()));
		try{
			pushService.pushCanceledWorks();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("停诊通知消息发送失败!");
		}

		System.out.println("定时任务停诊通知结束：" +DateUtil.dateFormat(new Date()));
	}

	@Scheduled(cron = "${push.cron}")
	@Async
	public void pushDischargeSettlementNot() {
		if(!pushOpen){
			return;
		}
		System.out.println("定时任务出院通知开始：" +DateUtil.dateFormat(new Date()));
		try{
			pushService.pushDischargeSettlementNot();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("出院通知消息发送失败!");
		}

		System.out.println("定时任务出院通知结束：" +DateUtil.dateFormat(new Date()));
	}

	@Scheduled(cron = "${push.cron}")
	@Async
	public void pushOperaStatus() {
		if(!pushOpen){
			return;
		}
		System.out.println("定时任务手术状态通知开始：" +DateUtil.dateFormat(new Date()));
		try{
			pushService.pushOperaStatus();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("手术状态通知消息发送失败!");
		}

		System.out.println("定时任务手术状态通知结束：" +DateUtil.dateFormat(new Date()));
	}

	@Scheduled(cron = "${push.cron}")
	@Async
	public void pushQueueInfo() {
		if(!pushOpen){
			return;
		}
		System.out.println("定时任务排队信息通知开始：" +DateUtil.dateFormat(new Date()));
		try{
			pushService.pushQueueInfo();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("排队信息通知消息发送失败!");
		}

		System.out.println("定时任务排队通知结束：" +DateUtil.dateFormat(new Date()));
	}

	@Scheduled(cron = "${push.cron}")
	@Async
	public void pushConfirmNot() {
		if(!pushOpen){
			return;
		}
		System.out.println("定时任务住院确认预约通知开始：" +DateUtil.dateFormat(new Date()));
		try{
			pushService.pushConfirmNot();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("住院确认预约通知消息发送失败!");
		}

		System.out.println("定时任务住院确认预约通知结束：" +DateUtil.dateFormat(new Date()));
	}

	@Scheduled(cron = "${push.cron}")
	@Async
	public void pushPayTradeNot() {
		if(!pushOpen){
			return;
		}
		System.out.println("定时任务诊间支付通知开始：" +DateUtil.dateFormat(new Date()));
		try{
			pushService.pushPayTradeNot();
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("诊间支付通知消息发送失败!");
		}

		System.out.println("定时任务诊间支付通知结束：" +DateUtil.dateFormat(new Date()));
	}
	
}
